/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nxlv2.nomad.accessdb.services;

import com.nxlv2.nomad.accessdb.dao.IClientDao;
import com.nxlv2.nomad.accessdb.dao.IUtilisateurDao;
import com.nxlv2.nomad.accessdb.dao.jdbc.JdbcClientDao;
import com.nxlv2.nomad.accessdb.dao.jdbc.JdbcUtilisateurDao;
import com.nxlv2.nomad.businessobjects.Adresse;
import com.nxlv2.nomad.businessobjects.Article;
import com.nxlv2.nomad.businessobjects.Client;
import com.nxlv2.nomad.businessobjects.Commande;
import com.nxlv2.nomad.businessobjects.Contact;
import com.nxlv2.nomad.businessobjects.Demande;
import com.nxlv2.nomad.businessobjects.Utilisateur;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Nastasia
 */
public class ClientServices {
    private static final IClientDao dao = new JdbcClientDao();
    private static final IUtilisateurDao daoU = new JdbcUtilisateurDao();    
    
    /**
     * 
     * @param client
     * @param utilisateur
     * @throws ServiceException 
     */
    public void create(Client client, Utilisateur utilisateur) throws ServiceException {        
        dao.saveClient(client);
        daoU.lierClientAUtilisateur(client, utilisateur);
    }
    
    /**
     * 
     * @param client
     * @throws ServiceException 
     */
    public void update(Client client) throws ServiceException {
        dao.updateClient(client);
    }
    
    /**
     * 
     * @param client
     * @throws ServiceException 
     */
    public void delete(Client client) throws ServiceException {
        dao.deleteClient(client.getIdAppli());
    }
    
    /**
     * 
     * @param id
     * @return
     * @throws ServiceException 
     */
    public Client get(int id) throws ServiceException {
        return dao.findClientById(id);
    }
    public Client getByIdbase(int id) throws ServiceException {
        return dao.findClientByIdbase(id);
    }
    
    /**
     * 
     * @param nom 
     */
    public boolean existNom(String nom, Utilisateur user){
        return dao.existNom(nom, user);
    }
    
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Contact> getContacts(Client client) throws ServiceException {
        return dao.getContactsParClient(client);
    }
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Contact> getContactsMaj(Client client) throws ServiceException {
        return dao.getContactsMajParClient(client);
    }
    
    /**
     * 
     * @param contact
     * @param client
     * @throws ServiceException 
     */
    public void linkContact (Contact contact ,Client client) throws ServiceException {
        dao.lierContactAClient(contact, client);
    }
    
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Adresse> getAdresses(Client client) throws ServiceException {
        return dao.getAdressesParClient(client);
    }
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Adresse> getAdressesMaj(Client client) throws ServiceException {
        return dao.getAdressesMajParClient(client);
    }
    
    /**
     * 
     * @param adresse
     * @param client
     * @throws ServiceException 
     */
    public void linkAdresse (Adresse adresse ,Client client) throws ServiceException {
        dao.lierAdresseAClient(adresse, client);
    }
    
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Article> getArticles(Client client) throws ServiceException {
        return dao.getArticlesParClient(client);
    }
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Article> getArticlesMaj(Client client) throws ServiceException {
        return dao.getArticlesMajParClient(client);
    }
    
    /**
     * 
     * @param article
     * @param client
     * @throws ServiceException 
     */
    public void linkArticle (Article article ,Client client) throws ServiceException {
        dao.lierArticleAClient(article, client);
    }
    
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Commande> getCommandes(Client client) throws ServiceException {
        return dao.getCommandesParClient(client);
    }
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Commande> getCommandesMaj(Client client) throws ServiceException {
        return dao.getCommandesMajParClient(client);
    }
    
    /**
     * 
     * @param commande
     * @param client
     * @throws ServiceException 
     */
    public void linkCommande (Commande commande ,Client client) throws ServiceException {
        dao.lierCommandeAClient(commande, client);
    }
    
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Demande> getDemandes(Client client) throws ServiceException {
        return dao.getDemandesParClient(client);
    }
    /**
     * 
     * @param client
     * @return
     * @throws ServiceException 
     */
    public List<Demande> getDemandesMaj(Client client) throws ServiceException {
        return dao.getDemandesMajParClient(client);
    }
    
    /**
     * 
     * @param demande
     * @param client
     * @throws ServiceException 
     */
    public void linkDemande (Demande demande ,Client client) throws ServiceException {
        dao.lierDemandeAClient(demande, client);
    }
    
}
